<?php
include("../lang/cn/company_type_config.php");

$str = "";
if($_GET['member_id']){
    $memIds = str_replace('，', ',', $_GET['member_id']);
    $str .= " and a.member_id in({$memIds})";
}
if($_GET['level']){
    $str .= " and b.level={$_GET['level']}";
}
if($_GET['payment_name']){
    $str .= " and a.payment_name='".strtolower($_GET['payment_name'])."'";
}
if($_GET['stime']){
    $stime = date('Y-m-d',strtotime($_GET['stime']));
    $str .= " and a.create_time>'{$stime}'";
}
if($_GET['etime']){
    $stime = date('Y-m-d',strtotime($_GET['etime']));
    $str .= " and a.create_time<'{$stime} 23:59:59'";
}

$sql = "select a.*,b.name as shop_name from ".MICROSHOPPAYLOG." AS a left join ".MICROSHOP." AS b on a.member_id=b.member_id where 1 {$str} order by a.create_time desc";
//=======分页=============
include_once("../includes/page_utf_class.php");
$page = new Page;
$page->listRows=20;
$db->query($sql);
$totalRows = $db->num_rows();
if (!$page->__get('totalRows')){
    $db->query($sql);
    $page->totalRows = $db->num_rows();
}
$sql .= "  limit ".$page->firstRow.",".$page->listRows;
$de['page'] = $page->prompt();
//=====================
$db->query($sql);
$de['list']=$db->getRows();
//总金额
$de['total_price'] = 0;
$sql = "select sum(a.price) as total_price from ".MICROSHOPPAYLOG." AS a left join ".MICROSHOP." AS b on a.member_id=b.member_id where 1 {$str}";
$db->query($sql);
$de['total_price'] = $db->fetchField('total_price');

foreach ($de['list'] as $k=>$v)
{
    $de['list'][$k]['payment_name'] = $bank_en_abbr[strtoupper($v['payment_name'])];
}

$tpl->assign('de',$de);
$tpl->assign('bank_en_abbr',$bank_en_abbr);
$tpl->display("shop_pay_log.htm");